<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Packaging</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Packaging' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../intern.html">Inter Modules</a></li><li><a href="index.html">building</a></li><li><a href="index.html#1">Chapter 1: Architecture</a></li><li><b>Packaging</b></li></ul></div>
<p class="purpose">To manage references to Inter packages which may or may not yet exist.</p>

<ul class="toc"><li><a href="1-pck.html#SP1">&#167;1. Package requests</a></li><li><a href="1-pck.html#SP4">&#167;4. The packaging state</a></li><li><a href="1-pck.html#SP9">&#167;9. Bubbles</a></li><li><a href="1-pck.html#SP12">&#167;12. Entry and exit</a></li><li><a href="1-pck.html#SP13">&#167;13. Incarnation</a></li><li><a href="1-pck.html#SP14">&#167;14. Functions</a></li><li><a href="1-pck.html#SP16">&#167;16. Generating inames</a></li><li><a href="1-pck.html#SP17">&#167;17. Bookkeeping</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Package requests.</b>See <a href="P-wtmd.html" class="internal">What This Module Does</a> for a fuller explanation, but briefly, a package
request represents a package which will eventually exist, if it does not exist
already. <a href="../inform7/index.html" class="internal">inform7</a> and other code-generation tools can make elaborate
shadowy hierarchies of such requests, with equally shadowy //inter_name//s
within them representing symbols which also do not exist yet. Eventually,
though, such tools need to make good on their promises and "incarnate" them.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">package_request</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">tree</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">eventual_name</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">eventual_type</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">package_request</span><span class="plain-syntax"> *</span><span class="identifier-syntax">parent_request</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> </span><span class="identifier-syntax">write_position</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">linked_list</span><span class="plain-syntax"> *</span><span class="identifier-syntax">iname_generators</span><span class="plain-syntax">; </span><span class="comment-syntax"> of </span><span class="extract"><span class="extract-syntax">inter_name_generator</span></span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">actual_package</span><span class="plain-syntax">; </span><span class="comment-syntax"> </span><span class="extract"><span class="extract-syntax">NULL</span></span><span class="comment-syntax"> until this is incarnated</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">package_request</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure package_request is accessed in 1/hl and here.</li></ul>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">package_request</span><span class="plain-syntax"> *</span><span class="function-syntax">Packaging::request</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">Packaging::request</span></span>:<br/><a href="1-pck.html#SP14">&#167;14</a>, <a href="1-pck.html#SP15">&#167;15</a><br/>Large-Scale Structure - <a href="1-ls.html#SP4">&#167;4</a>, <a href="1-ls.html#SP6">&#167;6</a>, <a href="1-ls.html#SP7">&#167;7</a>, <a href="1-ls.html#SP13">&#167;13</a>, <a href="1-ls.html#SP16">&#167;16</a><br/>Hierarchy Locations - <a href="1-hl.html#SP16">&#167;16</a>, <a href="1-hl.html#SP19">&#167;19</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="identifier-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pt</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">package_request</span><span class="plain-syntax"> *</span><span class="identifier-syntax">R</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">package_request</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">tree</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">eventual_name</span><span class="plain-syntax"> = </span><span class="identifier-syntax">name</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">eventual_type</span><span class="plain-syntax"> = </span><span class="identifier-syntax">pt</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">parent_request</span><span class="plain-syntax"> = </span><a href="1-in.html#SP8" class="function-link"><span class="function-syntax">InterNames::location</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">write_position</span><span class="plain-syntax"> = </span><span class="identifier-syntax">InterBookmark::at_start_of_this_repository</span><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">iname_generators</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">actual_package</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>In the debugging log, package requests are printed in a form looking a
little like URLs, except that they run in the reverse order, innermost first
and outermost last: to make this more visually clear, backslashes rather
than forward slashes are used as dividers.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Packaging::log</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">Packaging::log</span></span>:<br/>Building Module - <a href="1-bm.html#SP3_3">&#167;3.3</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">OUTPUT_STREAM</span><span class="plain-syntax">, </span><span class="reserved-syntax">void</span><span class="plain-syntax"> *</span><span class="identifier-syntax">vR</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">package_request</span><span class="plain-syntax"> *</span><span class="identifier-syntax">R</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">package_request</span><span class="plain-syntax"> *) </span><span class="identifier-syntax">vR</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">R</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;null-package&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">R</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax">++ &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"\\"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">actual_package</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"%S"</span><span class="plain-syntax">, </span><span class="identifier-syntax">InterPackage::name</span><span class="plain-syntax">(</span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">actual_package</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"'%n'"</span><span class="plain-syntax">, </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">eventual_name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">R</span><span class="plain-syntax"> = </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">parent_request</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. The packaging state.</b>At any given time, Inter code is being produced at a particular position
(in some incarnated package) and in the context of a given enclosure &mdash; see
<a href="1-ls.html#SP19" class="internal">LargeScale::package_type</a>. This is summarised by the following state:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">packaging_state</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> *</span><span class="identifier-syntax">saved_bookmark</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">package_request</span><span class="plain-syntax"> *</span><span class="identifier-syntax">saved_enclosure</span><span class="plain-syntax">;</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">packaging_state</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure packaging_state is private to this section.</li></ul>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>It is not legal to make any use of the following state, which exists only to
initialise variables to neutral contents (and thus to avoid warnings generated
because our C compiler is not able to prove that they will never be used in an
uninitialised state &mdash; though in fact they will not).
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">packaging_state</span><span class="plain-syntax"> </span><span class="function-syntax">Packaging::stateless</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">Packaging::stateless</span></span>:<br/><a href="1-pck.html#SP17">&#167;17</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">packaging_state</span><span class="plain-syntax"> </span><span class="identifier-syntax">PS</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">PS</span><span class="plain-syntax">.</span><span class="element-syntax">saved_bookmark</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">PS</span><span class="plain-syntax">.</span><span class="element-syntax">saved_enclosure</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">PS</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. </b>States are intentionally very lightweight, and in particular they contain
pointers to the bookmark structures rather than containing a copy thereof. But
those pointers have to point somewhere, and this is where: to a stack of
bookmarks.
</p>

<p class="commentary">The maximum here is beyond plenty: it's not the maximum hierarchical depth
of the Inter output, it's the maximum number of times that Inform interrupts
itself during compilation.
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">MAX_PACKAGING_ENTRY_DEPTH</span><span class="plain-syntax"> </span><span class="constant-syntax">128</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> *</span><span class="function-syntax">Packaging::push_state</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">Packaging::push_state</span></span>:<br/><a href="1-pck.html#SP7">&#167;7</a>, <a href="1-pck.html#SP12">&#167;12</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> </span><span class="identifier-syntax">IBM</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">packaging_entry_sp</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">MAX_PACKAGING_ENTRY_DEPTH</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"package stack overflow"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">packaging_entry_stack</span><span class="plain-syntax">[</span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">packaging_entry_sp</span><span class="plain-syntax">] = </span><span class="identifier-syntax">IBM</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> &amp;(</span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">packaging_entry_stack</span><span class="plain-syntax">[</span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">packaging_entry_sp</span><span class="plain-syntax">++]);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Packaging::pop_state</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">Packaging::pop_state</span></span>:<br/><a href="1-pck.html#SP12">&#167;12</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">packaging_entry_sp</span><span class="plain-syntax"> &lt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"package stack underflow"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">packaging_entry_sp</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>We store the current state at all times in the building site, and it has the
following invariant:
</p>

<ul class="items"><li>&#9679; The <span class="extract"><span class="extract-syntax">saved_bookmark</span></span> always points to a validly initialised <span class="extract"><span class="extract-syntax">inter_bookmark</span></span>;
</li><li>&#9679; The <span class="extract"><span class="extract-syntax">saved_enclosure</span></span> is always either <span class="extract"><span class="extract-syntax">NULL</span></span> or points to a package of a
type which is enclosing.
</li></ul>
<p class="commentary">In fact, <span class="extract"><span class="extract-syntax">saved_enclosure</span></span> is <span class="extract"><span class="extract-syntax">NULL</span></span> only fleetingly: as soon as the <span class="extract"><span class="extract-syntax">main</span></span>
package is created, very early on, the enclosure is always an enclosing package.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> *</span><span class="function-syntax">Packaging::at</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">Packaging::at</span></span>:<br/><a href="1-pck.html#SP9">&#167;9</a>, <a href="1-pck.html#SP13">&#167;13</a><br/>Large-Scale Structure - <a href="1-ls.html#SP20">&#167;20</a><br/>Produce - <a href="3-prd.html#SP5">&#167;5</a>, <a href="3-prd.html#SP12">&#167;12</a>, <a href="3-prd.html#SP19">&#167;19</a>, <a href="3-prd.html#SP20">&#167;20</a>, <a href="3-prd.html#SP21">&#167;21</a>, <a href="3-prd.html#SP22">&#167;22</a>, <a href="3-prd.html#SP31">&#167;31</a>, <a href="3-prd.html#SP33">&#167;33</a>, <a href="3-prd.html#SP34">&#167;34</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">current_state</span><span class="plain-syntax">.</span><span class="element-syntax">saved_bookmark</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Packaging::set_at</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">Packaging::set_at</span></span>:<br/>Produce - <a href="3-prd.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> </span><span class="identifier-syntax">to</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    *(</span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">current_state</span><span class="plain-syntax">.</span><span class="element-syntax">saved_bookmark</span><span class="plain-syntax">) = </span><span class="identifier-syntax">to</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">package_request</span><span class="plain-syntax"> *</span><span class="function-syntax">Packaging::enclosure</span><button class="popup" onclick="togglePopup('usagePopup8')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup8">Usage of <span class="code-font"><span class="function-syntax">Packaging::enclosure</span></span>:<br/><a href="1-pck.html#SP12">&#167;12</a>, <a href="1-pck.html#SP13">&#167;13</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">current_state</span><span class="plain-syntax">.</span><span class="element-syntax">saved_enclosure</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Packaging::initialise_state</span><button class="popup" onclick="togglePopup('usagePopup9')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup9">Usage of <span class="code-font"><span class="function-syntax">Packaging::initialise_state</span></span>:<br/><a href="1-pck.html#SP17">&#167;17</a><br/>Large-Scale Structure - <a href="1-ls.html#SP20">&#167;20</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">current_state</span><span class="plain-syntax">.</span><span class="element-syntax">saved_bookmark</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">        </span><a href="1-pck.html#SP6" class="function-link"><span class="function-syntax">Packaging::push_state</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">InterBookmark::at_start_of_this_repository</span><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">current_state</span><span class="plain-syntax">.</span><span class="element-syntax">saved_enclosure</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. </b>When we set the state, <span class="extract"><span class="extract-syntax">saved_enclosure</span></span> becomes the smallest package containing
(or equal to) <span class="extract"><span class="extract-syntax">PR</span></span>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Packaging::set_state</span><button class="popup" onclick="togglePopup('usagePopup10')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup10">Usage of <span class="code-font"><span class="function-syntax">Packaging::set_state</span></span>:<br/><a href="1-pck.html#SP12">&#167;12</a>, <a href="1-pck.html#SP13">&#167;13</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> *</span><span class="identifier-syntax">to</span><span class="plain-syntax">, </span><span class="reserved-syntax">package_request</span><span class="plain-syntax"> *</span><span class="identifier-syntax">PR</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">current_state</span><span class="plain-syntax">.</span><span class="element-syntax">saved_bookmark</span><span class="plain-syntax"> = </span><span class="identifier-syntax">to</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">PR</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">PR</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">parent_request</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (</span><a href="1-ls.html#SP19" class="function-link"><span class="function-syntax">LargeScale::package_type_enclosing</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">PR</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">eventual_type</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">PR</span><span class="plain-syntax"> = </span><span class="identifier-syntax">PR</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">parent_request</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">current_state</span><span class="plain-syntax">.</span><span class="element-syntax">saved_enclosure</span><span class="plain-syntax"> = </span><span class="identifier-syntax">PR</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. Bubbles.</b>Inter code is stored in memory as a linked list. This is fast and compact, but
can make it awkward to insert material other than at the end, particularly if
one insertion leads to another close by, midway in the process &mdash; which is
exactly what can happen when incarnating a nested set of packages.
</p>

<p class="commentary">It is also tricky to bookmark positions if nearby code may later be rewritten
or removed, as sometimes happens. A bookmark meaning "after this <span class="extract"><span class="extract-syntax">INV_IST</span></span>
instruction here" would be rendered invalid if that instruction were for some
reason removed.
</p>

<p class="commentary">Finally, because bookmarks can only refer to existing instruction positions,
it is difficult to place a bookmark in an empty package.
</p>

<p class="commentary">We avoid all these difficulties by placing "bubbles" at positions in the
linked list where we will later need to return and place new material.
A bubble is simply a pair of <span class="extract"><span class="extract-syntax">NOP_IST</span></span> (no operation) instructions; any
later inserted material will be placed between them. For example:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    ...</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inv</span><span class="plain-syntax"> </span><span class="identifier-syntax">Whatever</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">nop</span><span class="plain-syntax">                                       } </span><span class="identifier-syntax">this</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">bubble</span>
<span class="plain-syntax">        &lt;--- </span><span class="identifier-syntax">bookmark</span><span class="plain-syntax"> </span><span class="identifier-syntax">position</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">here</span><span class="plain-syntax">        }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">nop</span><span class="plain-syntax">                                       }</span>
<span class="plain-syntax">    ...</span>
</pre>
<p class="commentary">To insert a bubble at the current write-position:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> </span><span class="function-syntax">Packaging::bubble</span><button class="popup" onclick="togglePopup('usagePopup11')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup11">Usage of <span class="code-font"><span class="function-syntax">Packaging::bubble</span></span>:<br/><a href="1-pck.html#SP12">&#167;12</a>, <a href="1-pck.html#SP13">&#167;13</a><br/>Large-Scale Structure - <a href="1-ls.html#SP7">&#167;7</a>, <a href="1-ls.html#SP20">&#167;20</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="3-prd.html#SP19" class="function-link"><span class="function-syntax">Produce::nop</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> </span><span class="identifier-syntax">b</span><span class="plain-syntax"> = </span><span class="identifier-syntax">InterBookmark::snapshot</span><span class="plain-syntax">(</span><a href="1-pck.html#SP7" class="function-link"><span class="function-syntax">Packaging::at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><a href="3-prd.html#SP19" class="function-link"><span class="function-syntax">Produce::nop</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">b</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. </b>To insert a bubble somewhere else:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> </span><span class="function-syntax">Packaging::bubble_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> *</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="3-prd.html#SP19" class="function-link"><span class="function-syntax">Produce::nop_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">, </span><span class="constant-syntax">2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> </span><span class="identifier-syntax">b</span><span class="plain-syntax"> = </span><span class="identifier-syntax">InterBookmark::snapshot</span><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-prd.html#SP19" class="function-link"><span class="function-syntax">Produce::nop_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IBM</span><span class="plain-syntax">, </span><span class="constant-syntax">2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">b</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. </b>It's true that the Inter hierarchy does become fairly carbonated with these
bubbles, which costs us some memory; but in practice they cause no real speed
overhead, because <span class="extract"><span class="extract-syntax">nop</span></span> instructions are so quickly skipped over.
</p>

<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. Entry and exit.</b>Each PR contains a "write position". This is where emitted Inter code will go;
and it means that not all of the code inside a package needs to be written
at the same time. We can come and go as we please, adding code to packages
all over the hierarchy, simply by switching to the write position in the
package we wsnt to extend next.
</p>

<p class="commentary">That switching is called "entering" a package. Every entry must be followed
by a matching exit, which restores the write position to where it was before
the entry. (The one exception is that the very first entry, into <span class="extract"><span class="extract-syntax">main</span></span> &mdash;
see <a href="1-ls.html#SP20" class="internal">LargeScale::begin_new_tree</a> &mdash; is never followed by an exit.)
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">packaging_state</span><span class="plain-syntax"> </span><span class="function-syntax">Packaging::enter_home_of</span><button class="popup" onclick="togglePopup('usagePopup12')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup12">Usage of <span class="code-font"><span class="function-syntax">Packaging::enter_home_of</span></span>:<br/>Produce - <a href="3-prd.html#SP12">&#167;12</a>, <a href="3-prd.html#SP20">&#167;20</a>, <a href="3-prd.html#SP21">&#167;21</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">N</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="1-pck.html#SP12" class="function-link"><span class="function-syntax">Packaging::enter</span></a><span class="plain-syntax">(</span><a href="1-in.html#SP8" class="function-link"><span class="function-syntax">InterNames::location</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">N</span><span class="plain-syntax">));</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">packaging_state</span><span class="plain-syntax"> </span><span class="function-syntax">Packaging::enter</span><button class="popup" onclick="togglePopup('usagePopup13')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup13">Usage of <span class="code-font"><span class="function-syntax">Packaging::enter</span></span>:<br/>Large-Scale Structure - <a href="1-ls.html#SP7">&#167;7</a>, <a href="1-ls.html#SP20">&#167;20</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">package_request</span><span class="plain-syntax"> *</span><span class="identifier-syntax">R</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">R</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"no such package request"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">PACKAGING</span><span class="plain-syntax">, </span><span class="string-syntax">"Entering $X\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">R</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">packaging_state</span><span class="plain-syntax"> </span><span class="identifier-syntax">save</span><span class="plain-syntax"> = </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">tree</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">current_state</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="1-pck.html#SP13" class="function-link"><span class="function-syntax">Packaging::incarnate</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">R</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="1-pck.html#SP8" class="function-link"><span class="function-syntax">Packaging::set_state</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">tree</span><span class="plain-syntax">, &amp;(</span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">write_position</span><span class="plain-syntax">), </span><a href="1-pck.html#SP7" class="function-link"><span class="function-syntax">Packaging::enclosure</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">tree</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> *</span><span class="identifier-syntax">bubble</span><span class="plain-syntax"> = </span><a href="1-pck.html#SP6" class="function-link"><span class="function-syntax">Packaging::push_state</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">tree</span><span class="plain-syntax">, </span><a href="1-pck.html#SP9" class="function-link"><span class="function-syntax">Packaging::bubble</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">tree</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><a href="1-pck.html#SP8" class="function-link"><span class="function-syntax">Packaging::set_state</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">tree</span><span class="plain-syntax">, </span><span class="identifier-syntax">bubble</span><span class="plain-syntax">, </span><span class="identifier-syntax">R</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">PACKAGING</span><span class="plain-syntax">, </span><span class="string-syntax">"[%d] Current enclosure is $X\n"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">tree</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">packaging_entry_sp</span><span class="plain-syntax">, </span><a href="1-pck.html#SP7" class="function-link"><span class="function-syntax">Packaging::enclosure</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">tree</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">save</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Packaging::exit</span><button class="popup" onclick="togglePopup('usagePopup14')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup14">Usage of <span class="code-font"><span class="function-syntax">Packaging::exit</span></span>:<br/>Large-Scale Structure - <a href="1-ls.html#SP7">&#167;7</a><br/>Produce - <a href="3-prd.html#SP20">&#167;20</a>, <a href="3-prd.html#SP21">&#167;21</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="reserved-syntax">packaging_state</span><span class="plain-syntax"> </span><span class="identifier-syntax">save</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="1-pck.html#SP8" class="function-link"><span class="function-syntax">Packaging::set_state</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">save</span><span class="plain-syntax">.</span><span class="element-syntax">saved_bookmark</span><span class="plain-syntax">, </span><span class="identifier-syntax">save</span><span class="plain-syntax">.</span><span class="element-syntax">saved_enclosure</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="1-pck.html#SP6" class="function-link"><span class="function-syntax">Packaging::pop_state</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">PACKAGING</span><span class="plain-syntax">, </span><span class="string-syntax">"[%d] Back to $X\n"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">.</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">packaging_entry_sp</span><span class="plain-syntax">, </span><a href="1-pck.html#SP7" class="function-link"><span class="function-syntax">Packaging::enclosure</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">));</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. Incarnation.</b>The subtlety here is that if a package is incarnated, its parent must be
incarnated first, and we need to make sure that their write-position bubbles do
not lie inside each other: if they did, material compiled to the parent and to
the child would end up interleaved.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="function-syntax">Packaging::incarnate</span><button class="popup" onclick="togglePopup('usagePopup15')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup15">Usage of <span class="code-font"><span class="function-syntax">Packaging::incarnate</span></span>:<br/><a href="1-pck.html#SP12">&#167;12</a><br/>Large-Scale Structure - <a href="1-ls.html#SP4">&#167;4</a>, <a href="1-ls.html#SP6">&#167;6</a>, <a href="1-ls.html#SP7">&#167;7</a><br/>Inter Namespace - <a href="1-in.html#SP8">&#167;8</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">package_request</span><span class="plain-syntax"> *</span><span class="identifier-syntax">R</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">R</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"can't incarnate null request"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">actual_package</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">PACKAGING</span><span class="plain-syntax">, </span><span class="string-syntax">"Request to make incarnate $X\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">R</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax"> = </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">tree</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">package_request</span><span class="plain-syntax"> *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="1-pck.html#SP7" class="function-link"><span class="function-syntax">Packaging::enclosure</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">); </span><span class="comment-syntax"> This will not change</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">parent_request</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><a href="1-pck.html#SP13" class="function-link"><span class="function-syntax">Packaging::incarnate</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">parent_request</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> *</span><span class="identifier-syntax">save_IRS</span><span class="plain-syntax"> = </span><a href="1-pck.html#SP7" class="function-link"><span class="function-syntax">Packaging::at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="1-pck.html#SP8" class="function-link"><span class="function-syntax">Packaging::set_state</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, &amp;(</span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">parent_request</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">write_position</span><span class="plain-syntax">), </span><span class="identifier-syntax">E</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> </span><span class="identifier-syntax">package_bubble</span><span class="plain-syntax"> = </span><a href="1-pck.html#SP9" class="function-link"><span class="function-syntax">Packaging::bubble</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="1-pck.html#SP8" class="function-link"><span class="function-syntax">Packaging::set_state</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">package_bubble</span><span class="plain-syntax">, </span><span class="identifier-syntax">E</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">actual_package</span><span class="plain-syntax"> = </span><a href="3-prd.html#SP22" class="function-link"><span class="function-syntax">Produce::make_and_set_package</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">eventual_name</span><span class="plain-syntax">, </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">eventual_type</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">write_position</span><span class="plain-syntax"> = </span><a href="1-pck.html#SP9" class="function-link"><span class="function-syntax">Packaging::bubble</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="1-pck.html#SP8" class="function-link"><span class="function-syntax">Packaging::set_state</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">save_IRS</span><span class="plain-syntax">, </span><span class="identifier-syntax">E</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> </span><span class="identifier-syntax">package_bubble</span><span class="plain-syntax"> = </span><a href="1-pck.html#SP9" class="function-link"><span class="function-syntax">Packaging::bubble</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">package_bubble</span><span class="plain-syntax"> = </span><a href="1-pck.html#SP9" class="function-link"><span class="function-syntax">Packaging::bubble</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> *</span><span class="identifier-syntax">save_IRS</span><span class="plain-syntax"> = </span><a href="1-pck.html#SP7" class="function-link"><span class="function-syntax">Packaging::at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="1-pck.html#SP8" class="function-link"><span class="function-syntax">Packaging::set_state</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">package_bubble</span><span class="plain-syntax">, </span><span class="identifier-syntax">E</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">actual_package</span><span class="plain-syntax"> = </span><a href="3-prd.html#SP22" class="function-link"><span class="function-syntax">Produce::make_and_set_package</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">eventual_name</span><span class="plain-syntax">, </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">eventual_type</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">write_position</span><span class="plain-syntax"> = </span><a href="1-pck.html#SP9" class="function-link"><span class="function-syntax">Packaging::bubble</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="1-pck.html#SP8" class="function-link"><span class="function-syntax">Packaging::set_state</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">save_IRS</span><span class="plain-syntax">, </span><span class="identifier-syntax">E</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">PACKAGING</span><span class="plain-syntax">, </span><span class="string-syntax">"Made incarnate $X bookmark $5\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">R</span><span class="plain-syntax">, &amp;(</span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">write_position</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">actual_package</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>&#167;14. Functions.</b>Inter code has a standard layout for functions: an outer, enclosing, package of type
<span class="extract"><span class="extract-syntax">_function</span></span>, inside which is an iname <span class="extract"><span class="extract-syntax">call</span></span> for the actual code to call. All such
functions are produced by the following:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="function-syntax">Packaging::function</span><button class="popup" onclick="togglePopup('usagePopup16')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup16">Usage of <span class="code-font"><span class="function-syntax">Packaging::function</span></span>:<br/>Hierarchy Locations - <a href="1-hl.html#SP8_1_3">&#167;8.1.3</a>, <a href="1-hl.html#SP15_2">&#167;15.2</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">function_iname</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">translation</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">package_request</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">        </span><a href="1-pck.html#SP2" class="function-link"><span class="function-syntax">Packaging::request</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">function_iname</span><span class="plain-syntax">, </span><a href="1-ls.html#SP19" class="function-link"><span class="function-syntax">LargeScale::package_type</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"_function"</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">iname</span><span class="plain-syntax"> = </span><a href="1-in.html#SP6" class="function-link"><span class="function-syntax">InterNames::explicitly_named</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="string-syntax">"call"</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">translation</span><span class="plain-syntax">) </span><a href="1-in.html#SP11" class="function-link"><span class="function-syntax">InterNames::set_translation</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">iname</span><span class="plain-syntax">, </span><span class="identifier-syntax">translation</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">iname</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Packaging::housed_in_function</span><span class="plain-syntax">(</span><span class="identifier-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">iname</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">iname</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">package_request</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax"> = </span><a href="1-in.html#SP8" class="function-link"><span class="function-syntax">InterNames::location</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">iname</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">eventual_type</span><span class="plain-syntax"> == </span><a href="1-ls.html#SP19" class="function-link"><span class="function-syntax">LargeScale::package_type</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"_function"</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP15" class="paragraph-anchor"></a><b>&#167;15. </b>Datum packages.
These are very similar.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="function-syntax">Packaging::datum_text</span><button class="popup" onclick="togglePopup('usagePopup17')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup17">Usage of <span class="code-font"><span class="function-syntax">Packaging::datum_text</span></span>:<br/>Hierarchy Locations - <a href="1-hl.html#SP8_1_3">&#167;8.1.3</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">function_iname</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">identifier</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">package_request</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">        </span><a href="1-pck.html#SP2" class="function-link"><span class="function-syntax">Packaging::request</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">function_iname</span><span class="plain-syntax">, </span><a href="1-ls.html#SP19" class="function-link"><span class="function-syntax">LargeScale::package_type</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"_data"</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">iname</span><span class="plain-syntax"> = </span><a href="1-in.html#SP6" class="function-link"><span class="function-syntax">InterNames::explicitly_named</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">identifier</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">iname</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP16" class="paragraph-anchor"></a><b>&#167;16. Generating inames.</b>The following allows a sequence of different inames to be generated inside a
package: for example, <span class="extract"><span class="extract-syntax">Packaging::make_iname_within(R, I"acorn")</span></span> produces a
sequence of inames <span class="extract"><span class="extract-syntax">acorn1</span></span>, <span class="extract"><span class="extract-syntax">acorn2</span></span>, ..., as it's called over and over again.
</p>

<p class="commentary">The linked list here is invariably short, in practice, often with only 1 entry,
and so this naive algorithm is probably faster than using a hashed dictionary
of name stems.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="function-syntax">Packaging::make_iname_within</span><button class="popup" onclick="togglePopup('usagePopup18')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup18">Usage of <span class="code-font"><span class="function-syntax">Packaging::make_iname_within</span></span>:<br/>Hierarchy Locations - <a href="1-hl.html#SP19">&#167;19</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">package_request</span><span class="plain-syntax"> *</span><span class="identifier-syntax">R</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">what_for</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">R</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"no request"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">iname_generators</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">iname_generators</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NEW_LINKED_LIST</span><span class="plain-syntax">(</span><span class="reserved-syntax">inter_name_generator</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">inter_name_generator</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gen</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER_LINKED_LIST</span><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_name_generator</span><span class="plain-syntax">, </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">iname_generators</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::eq</span><span class="plain-syntax">(</span><span class="identifier-syntax">what_for</span><span class="plain-syntax">, </span><span class="identifier-syntax">gen</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">name_stem</span><span class="plain-syntax">))</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="1-in.html#SP7" class="function-link"><span class="function-syntax">InterNames::generated_in</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">, </span><span class="identifier-syntax">R</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">gen</span><span class="plain-syntax"> = </span><a href="1-in.html#SP2" class="function-link"><span class="function-syntax">InterNames::multiple_use_generator</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">what_for</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ADD_TO_LINKED_LIST</span><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_name_generator</span><span class="plain-syntax">, </span><span class="identifier-syntax">R</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">iname_generators</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="1-in.html#SP7" class="function-link"><span class="function-syntax">InterNames::generated_in</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, -1, </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">, </span><span class="identifier-syntax">R</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP17" class="paragraph-anchor"></a><b>&#167;17. Bookkeeping.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">site_packaging_data</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">packaging_state</span><span class="plain-syntax"> </span><span class="identifier-syntax">current_state</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_bookmark</span><span class="plain-syntax"> </span><span class="identifier-syntax">packaging_entry_stack</span><span class="plain-syntax">[</span><span class="constant-syntax">MAX_PACKAGING_ENTRY_DEPTH</span><span class="plain-syntax">];</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">packaging_entry_sp</span><span class="plain-syntax">;</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">site_packaging_data</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Packaging::clear_site_data</span><button class="popup" onclick="togglePopup('usagePopup19')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup19">Usage of <span class="code-font"><span class="function-syntax">Packaging::clear_site_data</span></span>:<br/>Building Module - <a href="1-bm.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">building_site</span><span class="plain-syntax"> *</span><span class="identifier-syntax">B</span><span class="plain-syntax"> = &amp;(</span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">site</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">B</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">current_state</span><span class="plain-syntax"> = </span><a href="1-pck.html#SP5" class="function-link"><span class="function-syntax">Packaging::stateless</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">B</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">spdata</span><span class="plain-syntax">.</span><span class="element-syntax">packaging_entry_sp</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="1-pck.html#SP7" class="function-link"><span class="function-syntax">Packaging::initialise_state</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>The structure site_packaging_data is private to this section.</li></ul>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="1-trn.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresscurrentchapter">1</li><li class="progresssection"><a href="1-bm.html">bm</a></li><li class="progresssection"><a href="1-ls.html">ls</a></li><li class="progresssection"><a href="1-ip.html">ip</a></li><li class="progresssection"><a href="1-org.html">org</a></li><li class="progresssection"><a href="1-hl.html">hl</a></li><li class="progresssection"><a href="1-lr.html">lr</a></li><li class="progresssection"><a href="1-trn.html">trn</a></li><li class="progresscurrent">pck</li><li class="progresssection"><a href="1-in.html">in</a></li><li class="progresschapter"><a href="2-is.html">2</a></li><li class="progresschapter"><a href="3-prd.html">3</a></li><li class="progressnext"><a href="1-in.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

